/**
 * 
 */
package infocluster.engine;

import infocluster.prototype.ExcelProcessTask;

import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Qi.Xi, GTO Intern, Standard Chartered
 *
 */
public class ExcelProcessEngine {
	
	private static ExcelProcessEngine engine = null;
	private static ArrayList<ExcelProcessTask> tasks = new ArrayList<ExcelProcessTask>();
	private static String month = "Jan";
	
	private ExcelProcessEngine(){}
	
	public static ExcelProcessEngine getEngine(){
		if(engine == null){
			engine = new ExcelProcessEngine();
		}
		return engine;
	}
	
	public boolean process() throws IOException{
		for(ExcelProcessTask task:tasks){
			task.execute();
		}
		tasks.clear();
		return true;
	}

	public void appendTask(ExcelProcessTask task) throws Exception {
		if(task != null)
			tasks.add(task);
		else throw new Exception();
	}
	
	public ExcelProcessTask getTask(int index) throws ArrayIndexOutOfBoundsException{
		if(index >= tasks.size())
			throw new ArrayIndexOutOfBoundsException();
		
		return tasks.get(index);
	}
	
	public void resetTask(){
		tasks.clear();
	}

	public String getMonth(){
		return month;
	}
	
	public void setMonth(String month) {
		ExcelProcessEngine.month = month;
	}
	
}
